home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / Bounds.h < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  148 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_Bounds_h)
  24. #define octave_Bounds_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. class ostream;
  31.  
  32. #include "dColVector.h"
  33.  
  34. class
  35. Bounds
  36. {
  37. public:
  38.  
  39.   Bounds (void)
  40.     : lb (), ub () { }
  41.  
  42.   Bounds (int n)
  43.     : lb (n, 0.0), ub (n, 0.0) { }
  44.  
  45.   Bounds (const ColumnVector l, const ColumnVector u)
  46.     : lb (l), ub (u)
  47.       {
  48.         if (lb.capacity () != ub.capacity ())
  49.       {
  50.         error ("inconsistent sizes for lower and upper bounds");
  51.         return;
  52.       }
  53.       }
  54.  
  55.   Bounds (const Bounds& a)
  56.     : lb (a.lb), ub (a.ub) { }
  57.  
  58.   Bounds& operator = (const Bounds& a)
  59.     {
  60.       if (this != &a)
  61.     {
  62.       lb = a.lower_bounds ();
  63.       ub = a.upper_bounds ();
  64.     }
  65.       return *this;
  66.     }
  67.  
  68.   ~Bounds (void) { }
  69.  
  70.   Bounds& resize (int n)
  71.     {
  72.       lb.resize (n);
  73.       ub.resize (n);
  74.  
  75.       return *this;
  76.     }
  77.  
  78.   double lower_bound (int index) const { return lb.elem (index); }
  79.   double upper_bound (int index) const { return ub.elem (index); }
  80.  
  81.   ColumnVector lower_bounds (void) const { return lb; }
  82.   ColumnVector upper_bounds (void) const { return ub; }
  83.  
  84.   int size (void) const { return lb.capacity (); }
  85.  
  86.   Bounds& set_bound (int index, double low, double high)
  87.     {
  88.       lb.elem (index) = low;
  89.       ub.elem (index) = high;
  90.       return *this;
  91.     }
  92.  
  93.   Bounds& set_bounds (double low, double high)
  94.     {
  95.       lb.fill (low);
  96.       ub.fill (high);
  97.       return *this;
  98.     }
  99.  
  100.   Bounds& set_bounds (const ColumnVector lb, const ColumnVector ub);
  101.  
  102.   Bounds& set_lower_bound (int index, double low)
  103.     {
  104.       lb.elem (index) = low;
  105.       return *this;
  106.     }
  107.  
  108.   Bounds& set_upper_bound (int index, double high)
  109.     {
  110.       ub.elem (index) = high;
  111.       return *this;
  112.     }
  113.  
  114.   Bounds& set_lower_bounds (double low)
  115.     {
  116.       lb.fill (low);
  117.       return *this;
  118.     }
  119.  
  120.   Bounds& set_upper_bounds (double high)
  121.     {
  122.       ub.fill (high);
  123.       return *this;
  124.     }
  125.  
  126.   Bounds& set_lower_bounds (const ColumnVector lb);
  127.   Bounds& set_upper_bounds (const ColumnVector ub);
  128.  
  129.   friend ostream& operator << (ostream& os, const Bounds& b);
  130.  
  131. protected:
  132.  
  133.   ColumnVector lb;
  134.   ColumnVector ub;
  135.  
  136. private:
  137.  
  138.   void error (const char *msg);
  139. };
  140.  
  141. #endif
  142.  
  143. /*
  144. ;;; Local Variables: ***
  145. ;;; mode: C++ ***
  146. ;;; End: ***
  147. */
  148.